#!/usr/bin/env  python2
__license__ = 'GPL v3'
'''
'''
import re

from calibre.web.feeds.recipes import BasicNewsRecipe


def classes(classes):
    q = frozenset(classes.split(' '))
    return dict(attrs={
        'class': lambda x: x and frozenset(x.split()).intersection(q)})


class ReadersDigest(BasicNewsRecipe):

    title = 'Readers Digest'
    __author__ = 'BrianG, Gobelinus'
    language = 'en'
    description = 'Readers Digest Feeds'
    no_stylesheets = True
    use_embedded_content = False
    oldest_article = 60
    max_articles_per_feed = 200

    language = 'en'
    remove_javascript = True
    remove_attributes = ['style']

    extra_css      = ''' h1 {font-family:georgia,serif;color:#000000;}
                        .mainHd{font-family:georgia,serif;color:#000000;}
                         h2 {font-family:Arial,Sans-serif;}
                        .name{font-family:Arial,Sans-serif; font-size:x-small;font-weight:bold; }
                        .date{font-family:Arial,Sans-serif; font-size:x-small ;color:#999999;}
                        .byline{font-family:Arial,Sans-serif; font-size:x-small ;}
                        .photoBkt{ font-size:x-small ;}
                        .vertPhoto{font-size:x-small ;}
                        .credits{font-family:Arial,Sans-serif; font-size:x-small ;color:gray;}
                        .credit{font-family:Arial,Sans-serif; font-size:x-small ;color:gray;}
                        .artTxt{font-family:georgia,serif;}
                        .caption{font-family:georgia,serif; font-size:x-small;color:#333333;}
                        .credit{font-family:georgia,serif; font-size:x-small;color:#999999;}
                        a:link{color:#CC0000;}
                        .breadcrumb{font-family:Arial,Sans-serif;font-size:x-small;}
                        '''

    feeds = [
        ('Food', 'http://www.rd.com/food/feed'),
        ('Health', 'http://www.rd.com/health/feed'),
        ('Home', 'http://www.rd.com/home/feed'),
        # ('Family', 'http://www.rd.com/family/feed'),
        # ('Money', 'http://www.rd.com/money/feed'),
        # ('Travel', 'http://www.rd.com/travel/feed'),
        ('True Stories', 'http://www.rd.com/true-stories/feed'),
        ('Advice', 'http://www.rd.com/advice/feed'),
    ]

    # cover_url = 'http://www.rd.com/images/logo-main-rd.gif'

    keep_only_tags = [
            classes('entry-header rd-article-dek'),
            dict(name='article', attrs={'class': lambda x: x and 'post-' in x}),
    ]
    remove_tags = [
        dict(attrs={'class': re.compile('rd-article--sidebar.*')}),
        dict(attrs={'class': ['rd-article--footer', 'rd-article--sharing']}),
        dict(attrs={'id': ['newsletter-form-container',
                           'confirmation-msg-container']}),
    ]
